package com.rc.saas.tenant.service.invoice;

import com.rc.saas.tenant.mapper.invoice.InvoiceMapper;
import com.rc.saas.tenant.model.invoice.Invoice;
import com.rc.saas.tenant.model.invoice.InvoiceExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * Created by sven on 2018-04-17
 */
@Service
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    private InvoiceMapper invoiceMapper;

    @Override
    public InvoiceMapper getMapper() {
        return invoiceMapper;
    }

    @Override
    public Invoice selectInvoiceByMigrateId(String tenantCode, Long migrateId) {
        InvoiceExample example = new InvoiceExample();
        example.createCriteria().andTenantCodeEqualTo(tenantCode).andMigrateIdEqualTo(migrateId);
        List<Invoice> list = invoiceMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(list)) {
            return list.get(0);
        }
        return null;
    }
}
